// app.js
App({
  onLaunch(options) {

    const that =this;
    const systemInfo= wx.getSystemInfoSync();
    const userInfo = wx.getStorageSync('userInfo');
    const menuButtonInfo= wx.getMenuButtonBoundingClientRect()

    that.globalData.navBarHeight_button = systemInfo.statusBarHeight+30;
    that.globalData.navBarHeight = systemInfo.statusBarHeight+44;
    that.globalData.menuRight = systemInfo.screenWidth-menuButtonInfo.right;
    that.globalData.menuTop = menuButtonInfo.top;
    that.globalData.menuHeight = menuButtonInfo.height;

    if (userInfo) {
      that.globalData.userId = userInfo.userId; // 单独设置，避免覆盖其他全局数据
      that.globalData.openid = userInfo.openId;
      that.globalData.sessionKey = userInfo.sessionKey;
      that.globalData.loginstate = userInfo.loginstate || "0";
    }   
    
  },
  
  globalData: {
    navBarHeight_button:0,
    navBarHeight:0,
    menuRight:0,
    menuTop:0,
    menuHeight:0,
    userId: null,
    openid: null,
    sessionKey: null,
    loginstate: "0",
    planSummary: {
      proteinTotal: '0.0',
      carbsTotal: '0.0',
      fatTotal: '0.0',
      caloriesTotal: '0.0'
    },
    meals: [
      { mealType: 1, mealName: '早餐', selectedFoods: [], totalCalories: 0, totalProtein: 0, totalFat: 0, totalCarbohydrate: 0 },
      { mealType: 2, mealName: '午餐', selectedFoods: [], totalCalories: 0, totalProtein: 0, totalFat: 0, totalCarbohydrate: 0 },
      { mealType: 3, mealName: '晚餐', selectedFoods: [], totalCalories: 0, totalProtein: 0, totalFat: 0, totalCarbohydrate: 0 },
      { mealType: 4, mealName: '加餐', selectedFoods: [], totalCalories: 0, totalProtein: 0, totalFat: 0, totalCarbohydrate: 0 }
    ]
  }
})
